package org.example.chat.dao;

import org.example.chat.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @author cheval
 */
@Repository
public interface UserRepository extends JpaRepository<User, String> {
    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    User findUserByUsername(String username);

    /**
     * 根据用户id查询用户信息，包括好友列表
     * @param id
     * @return
     */
    User findUserById(String id);

    User findByUsername(String username);


    @Modifying
    @Query(value = "update #{#entityName} t set t.faceBigImg = :bigImgPath, t.faceImg = :imgPath where t.id = :id")
    int updateUserHead(@Param("id") String id, @Param("imgPath") String imgPath, @Param("bigImgPath") String bigImgPath);
}
